package com.lagou.java.service.impl;

import com.lagou.java.annotation.Autowired;
import com.lagou.java.annotation.Service;
import com.lagou.java.annotation.Transactional;
import com.lagou.java.dao.AccountDao;
import com.lagou.java.pojo.Account;
import com.lagou.java.service.ITransferService;


@Service("transferService")
public class TransferServiceImpl implements ITransferService {

    @Autowired
    private AccountDao accountDao;

    @Transactional
    @Override
    public void transfer(String fromCardNo, String toCardNo, int money) throws Exception {
            Account from = accountDao.queryAccountByCardNo(fromCardNo);
            Account to = accountDao.queryAccountByCardNo(toCardNo);

            from.setMoney(from.getMoney() - money);
            to.setMoney(to.getMoney() + money);

            accountDao.updateAccountByCardNo(from);
//            int c = 1/0;
            accountDao.updateAccountByCardNo(to);
    }
}
